// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  env:"cloud2-4gncvam39e2323e9",
})
const db=cloud.database();
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
   const openid = cloud.getWXContext().OPENID
  event.openid=openid
  var res= await db.collection("pair").where({
    openid:openid
  }).count()
  if(res.total>0){
    await db.collection('pair').where({
      openid:openid
    }).update({
      data: event
    })
  }else{
    await db.collection('pair').add({
      data: event
    })
  }
  
}
